Skip to content

PR: Add badge for power values - #615

Merged
GermanBluefox merged 14 commits into
ioBroker:masterfrom
patricknitsch:master
Jun 29, 2026
Merged

PR: Add badge for power values#615
GermanBluefox merged 14 commits into
ioBroker:masterfrom
patricknitsch:master

Conversation

@patricknitsch

Copy link
Copy Markdown
Contributor
  • Add a badge for power values, like temperature and humidity on main folder
  • Use therefore alias from type information and change ACTUAL typ to number - value.power
  • Test in admin and web successful
image

Copilot AI and others added 13 commits June 11, 2026 11:33
The previous detection only checked the state named 'ACTUAL' for a
power role. Standard socket/plug devices expose their power measurement
as a separate state (e.g. ELECTRIC_POWER, role value.power) while ACTUAL
holds the on/off switch state (role indicator.power/switch), so power
was never detected.

Now, if no power role is found on ACTUAL, all states are scanned for a
matching stateRole. The found power state (not necessarily ACTUAL) is
then used for the subscription, ensuring the folder badge receives the
correct value.

https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
… is absent

The backend assigned stateRole exclusively from the state object's
common.role and then unconditionally deleted the type-detector's own
role property.  If an adapter omits common.role on a state (fairly
common for energy/power states), stateRole ended up undefined.  The
frontend's detection logic then found nothing to match against
POWER_ROLE_PATTERN, so no power badge was ever shown.

Now stateRole falls back to the type-detector's pattern role (via ??)
before the pattern role is deleted, so the frontend always receives a
usable role string even when the adapter has not set common.role.

https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
Power detection mirrors temperature/humidity: dedicated sensor devices
expose a standalone ACTUAL state with role value.power, so scanning
only ACTUAL (not every state) is the correct and consistent approach.

https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
…er devices

The ioBroker type-detector assigns the state name ELECTRIC_POWER (not ACTUAL)
to value.power states in socket/dimmer/light device types. The previous code
only checked the ACTUAL state's stateRole, so devices that have power in an
ELECTRIC_POWER state never triggered the badge.

This change adds a targeted fallback: after the ACTUAL-based check, if no
power role was detected yet but an ELECTRIC_POWER state exists, subscribe to
it for the power badge. The ACTUAL-based path is preserved unchanged for
standalone power-sensor devices (Types.info).

https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
The compiled admin bundle was stale — it predated all the TypeScript
changes that add power badge detection in the category header.
Running `cd src-admin && npm install && npm run build` produces a
fresh bundle (index-DRz4O4R1.js) that contains:

- POWER_ROLE_PATTERN matching value.power / value.level.power / watt / consumption
- subscribeWidgetsForStatus checking ACTUAL.stateRole for power role
- ELECTRIC_POWER fallback for socket/dimmer/light devices
- renderCategoryStatus/renderSubCategoryStatus rendering power value with ElectricBolt icon

https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
- Remove ELECTRIC_POWER fallback; power detection now exclusively uses
  the ACTUAL state's stateRole (same pattern as temperature/humidity).
  Standalone Info Channel sensors with common.role = 'value.power' on
  their ACTUAL state are the only target.
- Guard onStatusChange against a null state object: ioBroker delivers
  null to callbacks when a state is deleted, so store null instead of
  crashing or storing a garbage value. null → power stays null →
  badge is hidden (consistent with temperature/humidity behaviour).

https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
The www/ directory (served by the web adapter) had its own stale
compiled bundle that predated all power badge changes. Rebuilt from
src-www (which imports the same src-admin/src/WidgetsManager sources)
so that the web adapter view also shows power badges via ACTUAL.stateRole.

https://claude.ai/code/session_012kU6fNn1JUoEpMc1u9KBXK
@GermanBluefox
GermanBluefox requested a review from Copilot June 27, 2026 07:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@GermanBluefox
GermanBluefox merged commit 8dcb7bd into ioBroker:master Jun 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants